#ifndef MY_LOGGER_H 
#define MY_LOGGER_H 1


#define ERR_MAX_LINE 2048

#define FATAL_COLOR "\033[01;31m"
#define ERROR_COLOR "\033[22;31m"
#define WARNING_COLOR "\033[01;33m"
#define INFO_COLOR "\033[22;36m"
#define DEBUG_COLOR "\033[01;37m"
#define FINE_COLOR "\033[22;37m"
#define FINEST_COLOR "\033[22;37m"
#define NORMAL_COLOR "\033[0m"  
#define SET_CONSOLE_TEXT_COLOR(color) fprintf(stdout,color)

enum log_level {
    LOGL_FATAL,
    LOGL_ERROR,
    LOGL_WARN,
    LOGL_INFO,
    LOGL_DEBUG,
    LOGL_FINE,
    LOGL_FINEST
};


#ifdef __cplusplus
extern "C" {
#endif

void set_log_level(int level);
void set_log_fd(int fd);

void log_doit(int errflags,const char * fileName, uint32_t lineNumber,
                  const char * functionName , int level,const char *fmt,...);

#define LOG(errflags,level,...) do{ log_doit(errflags, __FILE__, __LINE__, __func__,level,__VA_ARGS__);}while(0)

#define FATAL(...)              do{ LOG(1,LOGL_FATAL,__VA_ARGS__); abort();}while(0)
#define DUMP(...)               do{ LOG(1,LOGL_FATAL,__VA_ARGS__); abort();}while(0)
#define ERROR(...)              do{ LOG(1,LOGL_ERROR,__VA_ARGS__); }while(0)
#define WARN(...)               do{ LOG(1,LOGL_WARN,__VA_ARGS__);  }while(0)
#define INFO(...)               do{ LOG(1,LOGL_INFO,__VA_ARGS__);  }while(0)
#define DEBUG(...)              do{ LOG(1,LOGL_DEBUG,__VA_ARGS__); }while(0)
#define FINE(...)               do{ LOG(1,LOGL_FINE,__VA_ARGS__);  }while(0)
#define FINEST(...)             do{ LOG(1,LOGL_FINEST,__VA_ARGS__);  }while(0)
#define ASSERT(...)             do{ LOG(1,LOGL_ERROR,__VA_ARGS__);assert(false);abort();}while(0)

#ifdef __cplusplus
}
#endif
#endif //MY_LOGGER_H
